import request from './http'
// const baseUrl = '/api/' // 基础url地址

// 登录接口
export const login = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/User/Login',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 修改密码接口
export const editPassword = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/User/ChangePassword',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 查找所有用户接口
export const getUsersList = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/User/GetUsers',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 查询全宗接口
export const getFondsList = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/ShowOff/GetFondsList',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 查询树接口
export const getTreeList = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/ShowOff/GetZtreeList',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 分类树权限接口
export const savePermission = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/ShowOff/SavePermission',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 查询案卷接口
export const getFolderList = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/ShowOff/GetArchivesVolEntityList',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 查询卷内接口
export const getFileList = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/ShowOff/GetArchivesFileList',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 查询全文接口
export const getFullList = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/ShowOff/GetAllInfosList',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 案卷表格数据xls导出
export const exportArchivesVol = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/ShowOff/ExportArchivesVol',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 卷内表格数据xls导出
export const exportArchivesFile = (parameter) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/ShowOff/ExportArchivesFile',
      method: 'post',
      data: parameter
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 下载文件
export const downloadFile = (parameter, fileName) => {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/ShowOff/DownloadFile',
      method: 'get',
      params: parameter,
      responseType: 'blob'
    }).then(res => {
      const data = res
      let url = window.URL.createObjectURL(data) // 将二进制文件转化为可访问的url
      var link = document.createElement('a')
      document.body.appendChild(link)
      link.href = url
      link.download = fileName
      link.click()
      link.remove()
      window.URL.revokeObjectURL(url)
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}
